// 屏幕分辨率
var _screen = window.screen.width + "*" + window.screen.height;

// 获取系统信息
function getSysInfo() {
    var ua = navigator.userAgent.toLowerCase();
    isWin10 = ua.indexOf("nt 10.0") > -1
    isWin7 = ua.indexOf("nt 6.1") > -1
    isVista = ua.indexOf("nt 6.0") > -1
    isWin2003 = ua.indexOf("nt 5.2") > -1
    isWinXp = ua.indexOf("nt 5.1") > -1
    isWin2000 = ua.indexOf("nt 5.0") > -1
    isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1)
    isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1)
    isAir = (ua.indexOf("adobeair") != -1)
    isLinux = (ua.indexOf("linux") != -1)
    var broser = "";
    if (isWin10) {
        sys = "Windows 10";
    } else if (isWin7) {
        sys = "Windows 7";
    } else if (isVista) {
        sys = "Vista";
    } else if (isWinXp) {
        sys = "Windows xp";
    } else if (isWin2003) {
        sys = "Windows 2003";
    } else if (isWin2000) {
        sys = "Windows 2000";
    } else if (isWindows) {
        sys = "Windows";
    } else if (isMac) {
        sys = "Macintosh";
    } else if (isAir) {
        sys = "Adobeair";
    } else if (isLinux) {
        sys = "Linux";
    } else {
        sys = "Unknow";
    }
    return sys;
}

// 获取浏览器类型
function GetBrowserType() {
    var ua = navigator.userAgent.toLowerCase();
    if (ua == null) {
        return "ie";
    } else if (ua.indexOf('chrome') != -1) {
        return "chrome";
    } else if (ua.indexOf('opera') != -1) {
        return "opera";
    } else if (ua.indexOf('msie') != -1) {
        return "ie";
    } else if (ua.indexOf('safari') != -1) {
        return "safari";
    } else if (ua.indexOf('firefox') != -1) {
        return "firefox";
    } else if (ua.indexOf('gecko') != -1) {
        return "gecko";
    } else {
        return "ie";
    }
}

// 获取浏览器版本
function GetBrowserVersion() {

    var ua = navigator.userAgent.toLowerCase();

    if (ua == null) return "null";

    else if (ua.indexOf('chrome') != -1) return ua.substring(ua.indexOf('chrome') + 7, ua.length).split(' ')[0];

    else if (ua.indexOf('opera') != -1) return ua.substring(ua.indexOf('version') + 8, ua.length);

    else if (ua.indexOf('msie') != -1) return ua.substring(ua.indexOf('msie') + 5, ua.length - 1).split(';')[0];

    else if (ua.indexOf('safari') != -1) return ua.substring(ua.indexOf('safari') + 7, ua.length);

    else if (ua.indexOf('gecko') != -1) return ua.substring(ua.indexOf('firefox') + 8, ua.length);

    else return "null";
}

var visit_system = getSysInfo();
var visit_browser = GetBrowserType();
var visit_browser_version = GetBrowserVersion();
var visit_resolution = _screen;
var visit_user;
var visit_user_sfzhm;
var visit_session_id;

function insertData(data) {
    $.ajax({
        type: "GET",
        url: "/tongji/insertData",
        data: data,
        dataType: "application/json; charset=utf-8",
        async: true,
        //crossDomain: true,
        success: function (data) {
        }
    });
}

function viewNum(visit_service){
	$.fetch({
		type: "GET",
		url: "/common/getSesId"
}).done(function(res){
	$.sessionStorageSetItem('visit_session_id', res.returnData.visit_session_id);

		var text = visit_system + visit_browser + visit_browser_version + visit_resolution + visit_service;
		var md5 = hex_md5(text);
		var data = {
			"visit_system": visit_system,
			"visit_browser": visit_browser,
			"visit_browser_version": visit_browser_version,
			"visit_resolution": visit_resolution,
			"visit_user": visit_user,
			"visit_user_sfzhm": visit_user_sfzhm,
			"visit_service": visit_service,
			"visit_session_id": $.sessionStorageGetItem('visit_session_id'),
			"md5": md5
		}
		insertData(data);
	});
}
